home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 8.5 KB | 233 lines | [TEXT/ttxt] |
- in module TextMenuModule
-
- --*******************************************************************************
- --* Class name: MenuButton
- --*
- --* Inherits from: TextPresenter and Actuator
- --* Class type: Concrete
- --* Component: User Interface
- --*
- --* Description: This is a subclass of TextPresenter and Actuator which
- --* facilitates the creation of hierarchical text menus.
- --* Top level menus and submenus are created in very much
- --* the same way. The only difference lies with the values
- --* of the supermenu and newMenu keywords. For top level
- --* menus, set supermenu to UNDEFINED and newMenu to TRUE.
- --* For submenus, set supermenu to its parent menu and newMenu
- --* to FALSE. To add new items (non menus) to the menu, use
- --* the addMenuItem method.
- --*
- --* Usage: main menubutton -
- --* mb := new MenuButton supermenu:UNDEFINED \
- --* label:"main menu" \
- --* newMenu:TRUE \
- --* width:100 \
- --* height:20
- --* sub menubutton -
- --* smb := new MenuButton supermenu:mb \
- --* label:"sub menu" \
- --* newMenu:FALSE \
- --* width:60 \
- --* height:20
- --* menu items -
- --* addmenuitem supermenu label authordata activateAction
- --*
- --* IVs: authordata
- --* activateAction
- --*
- --* Methods: addMenuItem
- --* press
- --* release
- --* activate
- --* init
- --*
- --* Required files: none
- --*
- --* Notes: If the action to be performed is a method, it must be
- --* defined as a method of the authordata.
- --*
- --* Also refer to bmpmenu.sx. Notice the similarities in the
- --* way the 2 versions of MenuButton are implemented.
- --*
- --* Author: Su Quek - Kaleida Labs, Inc.
- --*******************************************************************************
- class MenuButton (TextPresenter, Actuator)
- inst vars
- authordata
- activateAction
- end
-
- --*=============================================================================*
- --* Method name: addMenuItem
- --* Class: MenuButton
- --* Usage: addmenuitem self label authordata activateAction
- --* label - String object
- --* authordata - object
- --* activateAction - function
- --* Notes: If the activateAction is a method, it must be defined as a
- --* method of the authordata.
- --*-----------------------------------------------------------------------------*
- --* Description: Adds a terminal button (one which does not invoke another
- --* menu) and sets its authordata and action.
- --*=============================================================================*
- method addMenuItem self {class MenuButton} label authordata action ->
- (
- local menuItem := new MenuButton supermenu:self label:label newMenu:false
- menuItem.authordata := authordata
- menuItem.activateAction := action
-
- return menuItem
- )
-
- --*=============================================================================*
- --* Method name: press
- --* Class: MenuButton
- --* Usage: press self
- --*-----------------------------------------------------------------------------*
- --* Description: Sets the button to its pressed appearance.
- --* i.e. white letters on a black fill.
- --* Notes: This method can be overridden to display a different
- --* pressed appearance.
- --*=============================================================================*
- method press self {class MenuButton} ->
- (
- nextmethod self
- self.fill := blackBrush
- self.stroke := blackBrush
- setDefaultAttr self @brush whiteBrush
- )
-
- --*=============================================================================*
- --* Method name: release
- --* Class: MenuButton
- --* Usage: release self
- --*-----------------------------------------------------------------------------*
- --* Description: Sets the button to its released appearance.
- --* i.e. black letters on a white fill.
- --* Notes: This method can be overridden to display a different
- --* released appearance.
- --*=============================================================================*
- method release self {class MenuButton} ->
- (
- nextmethod self
- self.fill := whiteBrush
- self.stroke := blackBrush
- setDefaultAttr self @brush blackBrush
- )
-
- --*=============================================================================*
- --* Method name: activate
- --* Class: MenuButton
- --* Usage: activate self
- --*-----------------------------------------------------------------------------*
- --* Description: Sets the button to its released appearance.
- --* Executes the action to be performed when the button is
- --* clicked (activated).
- --* Notes: This method can be overridden to display a different
- --* released appearance.
- --*=============================================================================*
- method activate self {class MenuButton} ->
- (
- nextmethod self
-
- --*=========================================================================*
- --* Change the button to its released appearance.
- --*=========================================================================*
- self.fill := whiteBrush
- self.stroke := blackBrush
- setDefaultAttr self @brush blackBrush
-
- --*=========================================================================*
- --* Execute the action
- --*=========================================================================*
- if (self.activateAction <> undefined) do
- self.activateAction self.authordata self
- )
-
- --*=============================================================================*
- --* Method name: init
- --* Class: MenuButton
- --* Usage: init self [supermenu:<MenuButton>]
- --* [label:<String>]
- --* [newMenu:<Boolean>]
- --* [placement:<NameClass>]
- --* - (@menuDown, @menuRight, @menuAtPointer)
- --* [width:<Number>]
- --* [height:<Number>]
- --*-----------------------------------------------------------------------------*
- --* Description: Creates and initializes the TextPresenter to its default
- --* values unless another is explicitly given.
- --* Default values:
- --* supermenu - (undefined)
- --* label - (" ")
- --* newMenu - (true)
- --* placement - (@menuDown)
- --* width - (50)
- --* height - (20)
- --*=============================================================================*
- method init self {class MenuButton} #rest args #key supermenu:(undefined) \
- label:(" ") \
- newMenu:(true) \
- placement:(@menuDown) \
- width:(50) \
- height:(20) ->
- (
- apply nextmethod self boundary:(new rect x2:width y2:height) \
- target:label args
-
- self
- )
-
- --*=============================================================================*
- --* Method name: afterInit
- --* Class: MenuButton
- --* Usage: afterInit self [supermenu:<MenuButton>]
- --* [label:<String>]
- --* [newMenu:<Boolean>]
- --* [placement:<NameClass>]
- --* - (@menuDown, @menuRight, @menuAtPointer)
- --* [width:<Number>]
- --* [height:<Number>]
- --*-----------------------------------------------------------------------------*
- --* Description: Sets the appearance of the button. Adds the button to its
- --* supermenu or creates it's submenu as appropriate.
- --*=============================================================================*
- method afterInit self {class MenuButton} #rest args #key supermenu:(undefined) \
- label:(" ") \
- newMenu:(true) \
- placement:(@menuDown) \
- width:(50) \
- height:(20) ->
- (
- --*=========================================================================*
- --* Set the appearance of the button.
- --*=========================================================================*
- self.fill := whiteBrush
- self.stroke := blackBrush
- setDefaultAttr self @brush blackBrush
-
- setDefaultAttr self @size 10
- self.inset := new Point x:5 y:2
-
- --*=========================================================================*
- --* Create a submenu for this button
- --*=========================================================================*
- if newMenu do
- (
- local subMenu := new menu
- subMenu.placement := placement
- self.menu := subMenu
- )
-
- --*=========================================================================*
- --* Add this button to its supermenu
- --*=========================================================================*
- if (supermenu <> undefined) do
- append supermenu.menu self
-
- return self
- )
-
- "Loaded hiermenu.sx"
-
-